//
//  Tipe_SCR_WX.m
//  ZITHER
//
//  Created by weixin on 2019/5/13.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Tipe_SCR_WX.h"
#import "Tipe_WX_Image.h"
#import "Seach_FittrateSeting_VC_WX.h"
#import "MainAntistopVC_V4.h"
#import "Ugc_Release_VC_WX_V4.h"
#import "CustomCameraVC.h"
#import "MainDiscernVC.h"


@implementation Tipe_SCR_WX

- (instancetype)init
{
    self = [super init];
    if (self) {
//        self.backgroundColor = [UIColor redColor];
//        self.pagingEnabled = YES;
        //快速发布 快速识别 快速查表 快速去到某个品牌如@“劳力士“
//        [self addScrImage:@[@"1",@"2",@"2",@"2"]];
    }
    return self;
}


-(void)setArr:(NSArray<Tipe_Model_WX *> *)arr{
    _arr = arr;
    
    [self addScrImage];

}

-(void)addScrImage{
    
    if (self.arr.count == 0 || self.arr == nil) {
        self.hidden = YES;
        return;
    }
    
    CGFloat w = 280;
    CGFloat h = 160;
    CGFloat spacing = 10;

    
    self.hidden = NO;
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.contentSize = CGSizeMake(self.arr.count*(w+spacing)+10+85,0);
    self.userInteractionEnabled = YES;
    
    for (int j = 0; j<self.arr.count; j++) {
        [self addImage:j];
    }
}

-(void)addImage:(int)j{
    CGFloat w = 280;
    CGFloat h = 160;
    CGFloat spacing = 10;
    Tipe_WX_Image *imageV2 = [[Tipe_WX_Image alloc]init];
    imageV2.frame = CGRectMake(j*(w+spacing)+10,0, w,h);
    [self addSubview:imageV2];
    imageV2.model = self.arr[j];
    [[imageV2 addTag]subscribeNext:^(id  _Nullable x) {
        [self pushVC:j];
    }];
    [[imageV2.btn addTag]subscribeNext:^(id  _Nullable x) {
        [self pushVC:j];
    }];
    imageV2.tag = j +100;

}

-(void)pushVC:(int)j{
    if (j==0) {
        Seach_FittrateSeting_VC_WX *vc = [[Seach_FittrateSeting_VC_WX alloc]init];
        [self.getNav pushViewController:vc animated:YES];
    }else if (j==1){
        MainAntistopVC_V4 *vc = [[MainAntistopVC_V4 alloc] init];
        [self.getNav pushViewController:vc animated:YES];
    }else if (j==2){
        if (kUSER_INFO_MANAGER.userIsLogin) {
            [[serviceDefualt loadTopicDefaultSubjecte:nil]subscribeNext:^(ResponseData* x) {
                if (x.success) {
                    Ugc_Release_VC_WX_V4 *vc = [[Ugc_Release_VC_WX_V4 alloc]init];
                    vc.id = x.responseRawData[@"data"][@"id"];
                    vc.Topictitle = x.responseRawData[@"data"][@"title"];
                    [self.getNav pushViewController:vc animated:YES];
                }else{
                    [Tools showTips:x.errorInfo];
                }
            }];
        }else{
            [Tools pushSinge];
        }
    }else if (j==3){
        CustomCameraVC *vc = [[CustomCameraVC alloc] init];
        [self.getNav pushViewController:vc animated:YES];
    }else{
        if (kUSER_INFO_MANAGER.userIsLogin) {
            MainDiscernVC *vc = [[MainDiscernVC alloc]init];
            [self.getNav pushViewController:vc animated:YES];
            return ;
        }else{
            [Tools pushSinge];
        }
    }
    
}


@end
